package com.dayuanit.dy16.pay.alipayspringbootautoconfiguation.config;

import com.dayuanit.dy16.pay.alipayspringbootautoconfiguation.handler.AlipayHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({AlipayProperties.class})
public class DayuanPayAutoConfiguration {
    private AlipayProperties alipayProperties;

    public DayuanPayAutoConfiguration(AlipayProperties alipayProperties) {
        this.alipayProperties = alipayProperties;
        System.out.println(">>>>>>>>>>>>DayuanPayAutoConfiguration 构造方法");
    }

    @Bean
    @ConditionalOnMissingBean
    public AlipayHandler alipayHandler() {
        AlipayHandler alipayHandler = new AlipayHandler();
        alipayHandler.setAlipayPublicKey(alipayProperties.getAlipayPublicKey());
        alipayHandler.setAlipayServerGatewayUrl(alipayProperties.getAlipayServerGatewayUrl());
        alipayHandler.setAppid(alipayProperties.getAppid());
        alipayHandler.setCharset(alipayProperties.getCharset());
        alipayHandler.setMerchantPrivateKey(alipayProperties.getMerchantPrivateKey());
        alipayHandler.setNotifyUrl(alipayProperties.getNotifyUrl());
        alipayHandler.setReturnUrl(alipayProperties.getReturnUrl());
        alipayHandler.setSignType(alipayProperties.getSignType());
        return alipayHandler;
    }
}
